package cars

import (
	"parking-lot-go-admin/model"
	"time"
)

type CarsEntryStruct struct {
	Id         int       `gorm:"type:int(11) auto_increment; NOT NULL; primary_key"`
	ParkCode   string    `gorm:"type:varchar(255); COMMENT:'停车场码'"`
	ParkName   string    `gorm:"type:varchar(255); COMMENT:'停车场名称'"`
	CarNumber  string    `gorm:"type:varchar(255); COMMENT:'车牌号'"`
	InTime     time.Time `gorm:"type:datetime; COMMENT:'进入时间'"`
	InPhoto    string    `gorm:"type:varchar(255); COMMENT:'入场图片'"`
	SerialNo   string    `gorm:"type:varchar(255); COMMENT:'进场流水号'"`
	RegionCode string    `gorm:"type:varchar(255); COMMENT:'入场区域编号'"`
	RegionName string    `gorm:"type:varchar(255); COMMENT:'入场区域名称'"`
	CreatedAt  time.Time `gorm:"type:datetime"`
	UpdatedAt  time.Time `gorm:"type:datetime"`
	MemberId   int       `gorm:"type:int(11)"`
	CarNoColor int       `gorm:"type:tinyint(1); COMMENT:'车牌颜色'"`
	MuchId     string    `gorm:"type:varchar(255); COMMENT:'商户号'"`
	OrderNo    string    `gorm:"type:varchar(255)"`
	OrderType  int       `gorm:"type:tinyint(1); COMMENT:'订单类型'"`
	Repeated   int       `gorm:"type:tinyint(1); COMMENT:'重复进场'"`
	PushStatus int       `gorm:"type:tinyint(1); COMMENT:'推送状态'"`
	PushErrNum int       `gorm:"type:tinyint(1); COMMENT:'失败次数'"`
	PushTime   int       `gorm:"type:tinyint(1); COMMENT:'下次推送时间'"`
	IsAdmin    int       `gorm:"type:tinyint(1); COMMENT:'人工操作'"`
}

func (c *CarsEntryStruct) TableName() string {
	return "cars_entry"
}

// 今日活跃车场
func (c *CarsEntryStruct) ActiveParkLot() int {
	var count int64

	model.
		Db.
		Table(c.TableName()).
		Where("in_time >= ?", time.Now().Format("2006-01-02")).
		Group("park_code").
		Count(&count)

	return int(count)
}
